package cn.mugutu.finance.controller;

import cn.mugutu.finance.annotation.SysResource;
import cn.mugutu.finance.domain.system.DictionaryDetail;
import cn.mugutu.finance.domain.system.DictionaryType;
import cn.mugutu.finance.dto.BaseResult;
import cn.mugutu.finance.dto.EasyUIResult;
import cn.mugutu.finance.exception.BusinessException;
import cn.mugutu.finance.query.DictionaryDetailQuery;
import cn.mugutu.finance.service.system.DictionaryDetailService;
import cn.mugutu.finance.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/dictionaryDetail")
public class DictionaryDetailController extends BaseController {

    @Autowired
    private DictionaryDetailService dictionaryDetailService;

    @RequestMapping("/listUI")
    @SysResource(name = "字典明细管理", code = "dictionarydetail:listui")
    public String listUI() {
        return "dictionaryDetail/list";
    }

    @RequestMapping("/list")
    @ResponseBody
    public EasyUIResult<DictionaryDetail> list(DictionaryDetailQuery query, int page, int rows) {
        setEasyUIParamsInQuery(query, page, rows);
        Pager<DictionaryDetail> pager = dictionaryDetailService.findByPage(query);
        return new EasyUIResult<>(pager.getTotalCount(), pager.getRows());
    }

    @RequestMapping("/all")
    @ResponseBody
    public List<DictionaryDetail> all() {
        return dictionaryDetailService.findAll();
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public BaseResult saveOrUpdate(DictionaryDetail dictionaryDetail) {
        return dictionaryDetailService.saveOrUpdateDictionaryDetail(dictionaryDetail);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public BaseResult delete(Long id) {
        try {
            dictionaryDetailService.delete(id);
            return new BaseResult(true, "删除成功");
        } catch (Exception e) {
            throw new BusinessException("删除失败,请检查该字典明细是否已经存在了数据,或者联系系统管理员处理.");
        }
    }

    /**
     * 查询所有进入办案区原因
     * @return
     */
    @RequestMapping("/inCaseCause")
    @ResponseBody
    public List<DictionaryDetail> inCaseCause() {
        return dictionaryDetailService.findDictionaryDetailBySn(DictionaryType.INCASE_CAUSE);
    }

    /**
     * 查询所有随身物品保管措施
     * @return
     */
    @RequestMapping("/custodyMethod")
    @ResponseBody
    public List<DictionaryDetail> custodyMethod() {
        return dictionaryDetailService.findDictionaryDetailBySn(DictionaryType.CUSTODY_METHOD);
    }

    /**
     * 查询所有询问,迅问的房间
     * @return
     */
    @RequestMapping("/askRoom")
    @ResponseBody
    public List<DictionaryDetail> askRoom() {
        return dictionaryDetailService.findDictionaryDetailBySn(DictionaryType.ASK_ROOM);
    }

    /**
     * 查询所有信息采集项目
     * @return
     */
    @RequestMapping("/collectItem")
    @ResponseBody
    public List<DictionaryDetail> collectItem() {
        return dictionaryDetailService.findDictionaryDetailBySn(DictionaryType.COLLECT_ITEM);
    }

    /**
     * 查询所有报警情况
     * @return
     */
    @RequestMapping("/callPoliceStatus")
    @ResponseBody
    public List<DictionaryDetail> callPoliceStatus() {
        return dictionaryDetailService.findDictionaryDetailBySn(DictionaryType.CALL_POLICE_STATUS);
    }

    /**
     * 查询:是否
     * @return
     */
    @RequestMapping("/yesOrNo")
    @ResponseBody
    public List<DictionaryDetail> yesOrNo() {
        return dictionaryDetailService.findDictionaryDetailBySn(DictionaryType.YESORNO);
    }

    /**
     * 查询:所有最终离开原因
     * @return
     */
    @RequestMapping("/endLeaveCause")
    @ResponseBody
    public List<DictionaryDetail> endLeaveCause() {
        return dictionaryDetailService.findDictionaryDetailBySn(DictionaryType.END_LEAVE_CAUSE);
    }

    /**
     * 查询:所有随身物品处理情况
     * @return
     */
    @RequestMapping("/carryGoodsHandleStatus")
    @ResponseBody
    public List<DictionaryDetail> carryGoodsHandleStatus() {
        return dictionaryDetailService.findDictionaryDetailBySn(DictionaryType.carryGoods_Handle_Status);
    }
}
